package com.dwxt.mall.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.mall.admin.service.PromotionServiceAdmin;
import com.dwxt.mall.entity.PromotionProduct;
import com.dwxt.mall.service.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/mall/promotion")
@RestController
public class PromotionControllerAdmin {

    @Autowired
    private PromotionServiceAdmin promotionServiceAdmin;

    @Autowired
    private PromotionService promotionService;

    @RequestMapping("/createOrUpdate")
    public BaseResult createOrUpdate(PromotionProduct promotionProduct) {
        promotionServiceAdmin.createOrUpdate(promotionProduct);
        return BaseResult.ok();
    }

    @RequestMapping("/selectPromotion")
    public BaseResult selectPromotionProduct() {
        List<PromotionProduct> promotionProducts = promotionService.selectPromotionProduct();
        return BaseResult.ok(promotionProducts);
    }

    @RequestMapping("/delete")
    public BaseResult delete(Integer id){
        promotionServiceAdmin.delete(id);
        return BaseResult.ok();
    }
}
